function dianping() {
	var o = this;
	this.isload = 1;
	this.start = 0;
	this.pagesize = 10;
	this.scrollTopSize = 0;
	this.scrollTopSizeTemp = 0;
	this.tabID = 0;
	this.evalType = 1;
	this.UID = -1;
	this.isStop = 0;

	this.init = function() {
		o.UID = pageParm.UID;
		o.show();

		//var btn = $("#btn_submit");
		//btn.button().click(function () {
		//    var islogin = $(this).attr("name").split("_")[2];
		//    if (islogin == 0) location.href = '/reg/login.html';
		//    else o.submit($(":radio[name='clt_grade']:checked").val(), $("#clt_contents").val(), $("#clt_parm").val(), $(this));
		//});

		if ($('#dplist').length > 0)
			o.loaddel();
		return o;
	}

	this.tab = function(obj, id) {
		var _this = $(obj);
		var _list = _this.parent().parent();
		_list.find('li>a').removeClass('on');
		_this.addClass('on');

		o.tabID = id;
		o.isStop = 0;
		o.evalType = 1;
		o.start = 0;

		o.loadInfo();
		o.load(0);
	}
	//继续查看
	this.continue = function() {
		o.isStop = 0;
		o.evalType = 2;

		$(".pjlist").find('.sysdefault').remove();
		$(".pjlist").append(
			'<li class="load"><img src="https://res.psy525.cn/image/icon/loading.gif" alt="loading" />正在加载</li>');
		o.load(0);
	}

	this.loadInfo = function() {
		$(".pjlist").html(
			'<li class="load"><img src="https://res.psy525.cn/image/icon/loading.gif" alt="loading" />正在加载</li>');
	}

	this.show = function() {
		o.loadInfo();
		o.load(0);
		$(window).scroll(function() {
			o.scrollTopSize = $(this).scrollTop();

			setTimeout(function() {
				o.scrollTopSizeTemp = o.scrollTopSize;
			}, 0);

			var _items = $(".pjlist>.item");
			if (_items.length >= o.pagesize && $(".pjlist>.load").length <= 0 && o.isload == 1 && o.isStop == 0) {
				var scrollTop = $(this).scrollTop();
				var scrollHeight = $(document).height();
				var windowHeight = $(this).height();

				if (scrollTop + windowHeight >= scrollHeight - 60) {
					o.isload = 0;
					o.start = o.start + o.pagesize;

					$(".pjlist").append(
						'<li class="load"><img src="https://res.psy525.cn/image/icon/loading.gif" alt="loading" />正在加载</li>');
					setTimeout(function() {
						o.load(o.start);
					}, 500);
				}
			}
		});
	}
	//加载数据
	this.load = function(start) {
		var _list = $(".pjlist");
		var _parm = _list.attr("class");

		glb.ajax(glb.ajaxUrl + "loadEvaluateList", "html", "start=" + start + "&tabID=" + o.tabID + "&evalType=" + o.evalType +
			"&UID=" + o.UID,
			function() {
				o.isload = 0;
			},
			function(data) {
				if (data != '' && data.indexOf('没有了') == -1) {
					_list.find(".load").remove();
					if (o.isStop == 0) {
						_list.append(data);
					}
					if (data.indexOf('帮您过滤了一些参考不大的评价') != -1) {
						o.isStop = 1;
					}
				} else {
					_list.find('.load').text("没有了");
					o.isStop = 1;
				}

				o.isload = 1;
			},
			function() {
				_list.find(".load").remove();
				_list.append('<li class="load"><a href="javascript:void(0);" onclick="_dianping.load(' + start +
					')">加载失败，点击重新加载</a></li>');
				o.isload = 1;
			});
	}


	////提交点评
	//this.submit = function(grade, contents, parm, btn) {
	//    var txt = contents.replace(/(^\s*)|(\s*$)/g, "");
	//    if (txt == "") $("#clt_contents").focus();
	//    else if (txt.length < 2 || txt.length > 200) o.jalert("附言必须在2-200个字符之间");
	//    else if (grade < 0 || grade > 4) o.jalert("非法操作");
	//    else {
	//        glb.ajax(glb.ajaxUrl + "savedianping", "html", "grade=" + grade + "&contents=" + contents + "&parm=" + parm, function() { btn.prop("disabled", true); },
	//        function(data) {
	//            var row = data.substring(data.indexOf("@") + 1, data.length);
	//            var status = data.substring(0, data.indexOf("@"));
	//            btn.prop("disabled", false);
	//            if (status == 1) {
	//                $("#clt_contents").val('');
	//                $.jsuccess("点评成功", 250, null, null); //成功提示
	//                var list = $("#dplist");
	//                list.prepend(row);
	//                list.find(".no").remove();
	//            } else {
	//                if (status == 2) o.jalert("抱歉，系统检测到您有严重违规操作行为，已被禁止操作");
	//                else if (status == 3) o.jalert("操作失败，您提交的内容含有敏感关键词");
	//                else if (status == 4) o.jalert("附言必须在2-200个字符之间");
	//                else if (status == 5) o.jalert("点评仅限来访者账户");
	//                else if (status == 6) o.jalert("您今天已点评过该咨询师了");
	//                else if (status == 8) o.jalert("抱歉，您已被当前咨询师拉入黑名单");
	//                else if (status == 9) o.jalert("抱歉，您已被网站管理员拉入黑名单");
	//                else o.jalert("系统繁忙，请稍候提交");
	//            }
	//        }, function() { btn.prop("disabled", false); o.jalert("系统繁忙，请稍候提交"); });
	//    }
	//}
	//加载点评列表
	this.loaddp = function(parm, obj) {
		var _more = $(obj).parent();
		var _fail = "加载失败，<a href=\"javascript:void(0);\" onclick=\"_dianping.load('" + parm + "',this)\">[点击重新加载]</a>";
		glb.ajax(glb.ajaxUrl + "loaddianpinglist", "html", "parm=" + parm, function() {
				_more.html('数据加载中...');
			},
			function(data) {
				if (data == '' || data.indexOf('msgstatus') != -1) _more.html(_fail);
				else {
					_more.after(data);
					_more.remove();
					o.loaddel();
				}
			},
			function() {
				_more.html(_fail);
			});
	}
	//删除
	this.del = function(id, buid, uid, obj) {
		if (uid == -1) location.href = '/reg/login.html';
		else {
			var v = "确定要删除此条点评吗？";
			if (uid != buid) v +=
				'<br /><span class="del_blackform"><br /><input type="checkbox" id="clt_black_del" name="clt_black_del" /><label for="clt_black_del">同时将' +
				$(obj).parent().parent().find(".un").text() +
				'拉入黑名单</label><br />注：拉黑后此人将不能与您进行任何互动，可在“账户设置><a href="/uc/sets/black.html" target="_blank">黑名单</a>”中取消</span>';
			$.jconfirm("删除提示", v, 500, function() {
				var oldClick = $(obj).attr("onclick");
				var isblack = uid != buid && $("#clt_black_del").length > 0 && $("#clt_black_del").prop("checked") ? 1 : 0;
				glb.ajax(glb.ajaxUrl + "deldianping", "json", "id=" + id + "&buid=" + buid + "&isblack=" + isblack, function() {
					$(obj).attr("onclick", "");
				}, function(data) {
					var d = eval(data);
					if (d.status == 1) {
						$.jsuccess("删除" + (isblack == 1 ? "并拉黑" : "") + "成功", 250, null, null); //删除成功提示
						$(obj).parent().parent().parent().fadeOut();
					} else if (d.status == 2) o.jalert("删除失败,拉入黑名单时出现异常");
					else if (d.status == 3) {
						var _info =
							'删除失败，您的黑名单名额已满，需要管理黑名单才能操作！<br /><br /><span class="del_blackinfo"><span>确定要管理黑名单吗？<br /><br /></span>';
						_info += d.isdr == 1 ? '·&nbsp;可利用特权增加黑名单的名额<br />' : '';
						_info += '·&nbsp;可删除已拉黑的名额，以此来增加新名额</span>';
						$.jconfirm('删除提示', _info, 600, function() {
							$.jfnclose();
							location.href = "/uc/sets/black.html";
						});
					} else {
						$(obj).attr("onclick", oldClick);
						o.jalert("系统繁忙，请稍候提交");
					}
				}, function() {
					$(obj).attr("onclick", oldClick);
					o.jalert("系统繁忙，请稍候提交");
				});
			});
		}
	}
	this.loaddel = function() {
		$("#dplist>.item").mouseover(function() {
			$(this).find("span>.del").show();
		}).mouseout(function() {
			$(this).find("span>.del").hide();
		});
	}
	//提示信息
	this.jalert = function(info) {
		$.jalerttimer("操作提示", info, 550, function() {
			$.jfnclose();
		}, null);
	}
}
var _global = null;
var _dianping = null;
var _evaluate = null;
$(function() {
	_global = new global().init();
	_dianping = new dianping().init();
	_evaluate = _dianping;
});
